-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add standard acknowledgement to channels and apply usage in ibc transfer #7263
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7263 +/- ##
==========================================
+ Coverage 55.13% 55.17% +0.03%
==========================================
Files 584 584
Lines 40506 40535 +29
==========================================
+ Hits 22335 22366 +31
+ Misses 16301 16300 -1
+ Partials 1870 1869 -1 |
Success: true, | ||
Error: "", | ||
} | ||
acknowledgement := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what to put here since it is not specified in ICS20 at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know either, but this seems like a fair non-empty success flag.
(Also 1 is a nice replacement for true
and auto-convert in many languages)
@@ -356,19 +352,10 @@ func (am AppModule) OnAcknowledgementPacket( | |||
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), | |||
sdk.NewAttribute(types.AttributeKeyDenom, data.Denom), | |||
sdk.NewAttribute(types.AttributeKeyAmount, fmt.Sprintf("%d", data.Amount)), | |||
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), | |||
sdk.NewAttribute(types.AttributeKeyAck, fmt.Sprintf("%v", ack)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts? or should I add a switch to check the type and emit a bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have it emit the result or error message as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of the bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, let me know if you agree, with specs as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the usage above:
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", err != nil))
We could use %v
instead (or as well), but it would be nice to have them both the same (the attributes in the two different functions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yea, I agree. Will update in a followup. We discussed standardizing IBC events on the IBC call which I think would be very useful in cases like this where there are multiple way to represent the same information
@@ -336,7 +332,7 @@ func (am AppModule) OnAcknowledgementPacket( | |||
packet channeltypes.Packet, | |||
acknowledgement []byte, | |||
) (*sdk.Result, error) { | |||
var ack types.FungibleTokenPacketAcknowledgement | |||
var ack channeltypes.Acknowledgement | |||
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we use the cdc in the keeper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the keeper codec is a BinaryMarshaler, thus it doesn't support JSON unmarshal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff.
Thanks @colin-axner
Success: true, | ||
Error: "", | ||
} | ||
acknowledgement := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know either, but this seems like a fair non-empty success flag.
(Also 1 is a nice replacement for true
and auto-convert in many languages)
@@ -356,19 +352,10 @@ func (am AppModule) OnAcknowledgementPacket( | |||
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), | |||
sdk.NewAttribute(types.AttributeKeyDenom, data.Denom), | |||
sdk.NewAttribute(types.AttributeKeyAmount, fmt.Sprintf("%d", data.Amount)), | |||
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), | |||
sdk.NewAttribute(types.AttributeKeyAck, fmt.Sprintf("%v", ack)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the usage above:
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", err != nil))
We could use %v
instead (or as well), but it would be nice to have them both the same (the attributes in the two different functions)
} | ||
|
||
// ValidateBasic performs a basic validation of the acknowledgement | ||
func (ack Acknowledgement) ValidateBasic() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 🙂
if !ack.Success { | ||
func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData, ack channeltypes.Acknowledgement) error { | ||
switch ack.Response.(type) { | ||
case *channeltypes.Acknowledgement_Error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we test this somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think it should be tested by the commented tests. I wanted to uncomment the tests in a followup pr to keep this pr lightweight. There is an issue for this #7261
return k.refundPacketToken(ctx, packet, data) | ||
default: | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, can you add a note on why we return nil instead of an error?
@@ -336,7 +332,7 @@ func (am AppModule) OnAcknowledgementPacket( | |||
packet channeltypes.Packet, | |||
acknowledgement []byte, | |||
) (*sdk.Result, error) { | |||
var ack types.FungibleTokenPacketAcknowledgement | |||
var ack channeltypes.Acknowledgement | |||
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the keeper codec is a BinaryMarshaler, thus it doesn't support JSON unmarshal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…k into colin/6963-standard-ack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Description
Adds standard acknowledgement definition as defined by ICS 04 and updates ibc-transfer to use this acknowledgement
closes: #6963
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes